Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-beforeexit-event #10121

Closed

Conversation

radelmann
Copy link
Contributor

@radelmann radelmann commented Dec 5, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

Description of change
  • replaced var with const or let.
  • removed all console.log() statements.
  • removed deaths and revivals vars.
  • wrapped beforexit listener callbacks with
    common.mustCall().
  • removed exit event listener.

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 5, 2016
@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch from cda4900 to 48691c1 Compare December 5, 2016 06:32
@mscdex mscdex added the process Issues and PRs related to the process subsystem. label Dec 5, 2016

function tryTimer() {
const tryTimer = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?


function tryListen() {
const tryListen = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why is this necessary?

}
};

process.on('beforeExit', () => { deaths++; });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just get rid of the revivals and deaths variables and just use common.mustCall() with the expected number of calls.

@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch 2 times, most recently from faa9ace to 0eddb09 Compare December 5, 2016 08:03
}

function beforeProcess() {
console.log('before process');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better as before listener?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were trying to remove all logging in tests unless required by the test?

Copy link
Contributor

@Fishrock123 Fishrock123 Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe but it just gets swallowed anyways?

The console.log are definitely not required though so ¯\_(ツ)_/¯

assert.equal(3, revivals);
process.on('exit', () => {
common.mustCall(beforeExit, 4);
common.mustCall(beforeProcess, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how this works. :)

You will need to wrap the callback that you want to call before using it (as in, the variables at lines 9-15 already need the wrappers). Then the exit event listener can be removed.

@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch 5 times, most recently from cba9aff to 3e3fe42 Compare December 5, 2016 21:33
@radelmann
Copy link
Contributor Author

@Fishrock123 requested changes have been completed, any additional feedback would be much appreciated. Thanks:-)


process.on('beforeExit', function() { deaths++; });
const beforeExit = common.mustCall(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be:

process.on('beforeExit', common.mustCall(() => {}), 4);

this.close();
})
.on('error', (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'error' handler can be removed since node will already throw if there are no 'error' handlers.

setImmediate(function() {
revivals++;
setImmediate(() => {
beforeListener();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I had in mind instead of this is to wrap the enclosing function in common.mustCall(), for example:

setImmediate(common.mustCall(() => {
  process.once('beforeExit', common.mustCall(tryTimer));
}));

setTimeout(function() {
console.log('timeout cb, do another once beforeExit');
revivals++;
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this would instead be:

setTimeout(common.mustCall(() => {
  process.once('beforeExit', common.mustCall(tryListen));
}));

process.once('beforeExit', tryListen);
}, 1);
}

function tryListen() {
console.log('create a server');
net.createServer()
.listen(0)
.on('listening', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one would just be

.on('listening', common.mustCall(() => {
  this.close();
}));

return;
}, 3);

process.on('beforeExit', beforeExit);

process.once('beforeExit', tryImmediate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be:

process.once('beforeExit', common.mustCall(tryImmediate));

@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch from 29b7e97 to 8f8c63e Compare December 6, 2016 20:35
@Fishrock123
Copy link
Contributor

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a little nit

}, 4);

const beforeListener = common.mustCall(() => {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can probably just be () => {}


process.on('beforeExit', function() { deaths++; });
const beforeExit = common.mustCall(() => {}, 4);
Copy link
Contributor

@mscdex mscdex Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, I think we can actually get rid of this separate check entirely by just adding a

process.on('beforeExit', common.mustCall(() => {}));

after the this.close() in tryListen().

@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch from 8f8c63e to 5a9a898 Compare December 6, 2016 22:05
Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex
Copy link
Contributor

mscdex commented Dec 7, 2016

LGTM

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mhdawson
Copy link
Member

mhdawson commented Dec 7, 2016

CI clean except for failure on smartos which seems unrelated to this test. Opened #10166 to track that issue separately.

@mhdawson
Copy link
Member

mhdawson commented Dec 7, 2016

@radelmann, one last thing before we land. We need your full name "Rob Adelmann" as the author for the commit. I could fix that as part of landing but probably better if you do this in your env and re-push. You should be able to change with: git commit --amend --author="Rob Adelmann adelmann@adobe.com" and if you can also update your git config so that future commits also have your full name that would be good.

@addaleax
Copy link
Member

addaleax commented Dec 7, 2016

We need your full name "Rob Adelmann" as the author for the commit.

Just for clarity, feel free to use the name and email address you would like your commits to be credited to (or indicate that just “adelmann” is actually exactly what you prefer).

- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.
@radelmann radelmann force-pushed the test-beforeexit-event-refactor branch from 5a9a898 to 4b254d8 Compare December 7, 2016 17:26
@radelmann
Copy link
Contributor Author

@mhdawson & @addaleax, commit author amended. Let me know if you need anything else, thanks.

@addaleax
Copy link
Member

addaleax commented Dec 7, 2016

Landed in 8960383, thanks for the contribution! 

@addaleax addaleax closed this Dec 7, 2016
addaleax pushed a commit that referenced this pull request Dec 7, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: #10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
addaleax pushed a commit that referenced this pull request Dec 8, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: #10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
addaleax pushed a commit to addaleax/node that referenced this pull request Dec 8, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: nodejs#10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
@italoacasas italoacasas mentioned this pull request Dec 15, 2016
MylesBorins pushed a commit that referenced this pull request Dec 20, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: #10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: #10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: #10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This was referenced Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants